<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript">
<!--

//-->
</script>
<style>
<!--
 	.btn_newsadd{
 		margin-left:50px;
 	}
-->
</style>
<link href="css/style.css" rel="stylesheet" type="text/css" /> 
<link href="<%=path %>/resources/date/bootstrap-datetimepicker.min.css" rel="stylesheet" type="text/css" /> 
<link rel="stylesheet" type="text/css" href="<%=path %>/css/bootstrap.min.css" />
<script type="text/javascript" src="<%=path %>/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=path %>/js/bootstrap.js"></script>
<script type="text/javascript" src="<%=path %>/resources/date/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="<%=path %>/resources/date/bootstrap-datetimepicker.zh-CN.js"></script>

    <script type="text/javascript" src="<%=path %>/js/resources/jquery.md5.js"></script>

    <jsp:include page="common.jsp"></jsp:include>
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li>用户管理</li>
    <li>用户注册</li> 
    </ul>
    </div>
    
    <div class="formbody">
    
    <div class="formtitle"><span>基本信息</span></div>
    
    <ul class="forminfo">
    <li><label>用户账号</label><input name="account" id="account" type="text" class="dfinput" style="width:60%;"/><i>*账号不能超过20个字符</i></li>
    <li><label>用户密码</label><input name="pwd" id="pwd" type="password" class="dfinput" style="width:60%;"/><i></i></li>
    <li><label>生日</label><input name="birthday" id="birthday" type="text" class="dfinput form_datetime" /><i>最晚时间为当前时间</i></li>
    <li><label>用户备注</label><input name="remark" id="remark" type="text" class="dfinput" style="width:60%;"/></li>
    <li><label>&nbsp;</label>
    	<input name="" id="user_save" type="button" class="btn btn-primary btn_newsadd" value="确认保存"/>
    	<input name="" id="user_reset" type="button" class="btn btn-primary btn_newsadd" value="重置"/>
    </li>
    </ul>
    
    
    </div>
    
 <script type="text/javascript" >
 

 var path='<%=basePath%>';
 $(".form_datetime").datetimepicker({
		language: 'zh-CN',
		format: 'yyyy-mm-dd',
		autoclose:true,
		endDate:new Date()
 });
 
$(function (){
	 $("#user_save").click(regist);
});

 function regist(){
 	if(validUserField()){
 		$.ajax({
 			type:"POST",
 			url:path+"/adminUserAction_regist.action",
 			data:{
 				account:$("#account").val(),
 				pwd:$.md5($("#pwd").val()),
 				birthday:$("#birthday").val(),
 				remark:$("#remark").val(),
 			},
 			dataType:"json",
 			success:function (res){
 					debugger;
 				/* res=eval('('+res+')'); */
 				if(res.rescode=='100'){ 
 					alert(res.msg);
 					$("input[type=text]").val('');
 				}else{
 					alert(res.msg);
 				}
 			}
 		});
 	}
 }

 function validUserField(){
	 var v=$("input[name=account]").val();
	 if(!v){
		 showWarnMsg("用户账号不能为空");
		 return false;
	 }
	 if(v.length<2 || v.length>20){
		 showWarnMsg("用户账号不能少于2个字符，不能大于20个字符");
		 return false;
	 }
	 $.post(path+"/adminUserAction_validAcc.action",{
		 account:$("#account").val()
	 },function(result){
		 result=eval('('+result+')');
		 if(result.rescode=='-100'){
			 showWarnMsg(result.msg);
			 return false;
		 }
	 });
	 var c=$("input[name=pwd]").val();
	 if(!c){
		 showWarnMsg("用户密码不能为空");
		 return false;
	 }
	 if(c.length<6 ){
		 showWarnMsg("用户密码不能少于6个字符");
		 return false;
	 }
	 return true;
 }
  
 $("input[name=account]").bind("blur",function(){
	 var v=$("input[name=account]").val();
	 if(!v){
		 showWarnMsg("用户账号不能为空");
		 return ;
	 }
	 if(v.length<6 || v.length>20){
		 showWarnMsg("用户账号不能少于6个字符，不能大于20个字符");
		 return ;
	 }
	 $.post(path+"/adminUserAction_validAcc.action",{
		 account:$("#account").val()
	 },function(result){
		 result=eval('('+result+')');
		 if(result.rescode=='-100'){
			 showWarnMsg(result.msg);
			 return;
		 }
	 });
 });
 $("input[name=pwd]").bind("blur",function(){
	 var c=$("input[name=pwd]").val();
	 if(!c){
		 showWarnMsg("用户密码不能为空");
		 return ;
	 }
	 if(c.length<6 ){
		 showWarnMsg("用户密码不能少于6个字符");
		 return ;
	 }
 });
 
 $("#user_reset").click(function(){ 
		/*jquery 没有reset 方法，使用dom 的，reset 不能重置 textarea，手动重置 textarea */
		$("input[type=text]").val('');
	});
 
 </script>